package com.itqf.aop.advice;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * MethodBeforeAdvice  前置
 * MethodInterceptor  环绕  前后都会执行
 * AfterReturningAdvice  后置
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2021/1/14
 * @Time: 下午2:49
 */
public class MyAdvice implements
        MethodBeforeAdvice,MethodInterceptor,AfterReturningAdvice {

    /**
     * 日志
     * 开启事务
     * @param method
     * @param objects
     * @param o
     * @throws Throwable
     */
    @Override
    public void before(Method method, Object[] objects, Object o) throws Throwable {
        System.out.println("前......"+method.getName()+"---"+Arrays.toString(objects));
    }

    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        System.out.println("环绕---前......");

        Object r = methodInvocation.proceed();

        System.out.println("环绕---后......");
        return r;
    }

    @Override
    public void afterReturning(Object o, Method method, Object[] objects, Object o1) throws Throwable {
        System.out.println("后......"+method.getName()+"---"+Arrays.toString(objects));

    }
}
